<template>
    <view class="container">
        <header-bar :config="config"></header-bar>
        <view class="main">
            <view class="card-group">
                <card-cell-input ref="name" :showLabel="false" :value="name" placeholder="请输入姓名"></card-cell-input>
            </view>
            <button class="btn btn-success btn-save" @click="submit">保存</button>
        </view>
    </view>
</template>

<script>
import { mapMutations, mapGetters } from "vuex"
import { UpdateGuideName } from "@/service/api/user.js"
import cardCellInput from "@/components/common/cell/card-cell-input.vue"
import storage from "@/uni-sub-base/utils/storage.js"
export default {
    components: {
        cardCellInput,
    },
    data() {
        return {
            config: {
                title: "修改姓名",
                centerSlot: true,
            },
            name: "",
        }
    },
    mounted() {},
    onLoad(e) {
        this.name = e.name
    },
    methods: {
        ...mapMutations(["UP_ME_VIEW", "SET_AUTH"]),
        //密码修改
        submit() {
            if (this.$refs.name.getValue() == "") {
                this.easyToast("请输入姓名")
                return
            }
            let param = {
                type: 1,
                name: this.$refs.name.getValue(),
            }
            let path = "?type=1&name=" + this.$refs.name.getValue()
            UpdateGuideName(param, path).then((res) => {
                if (res.State == 1) {
                    let userInfo = storage.getCache("userInfo")
                    userInfo.RealName = param.name
                    storage.setCache("userInfo", userInfo)
                    let token = res.Data
                    if (token) {
                        storage.setCache("token", token)
                        this.SET_AUTH(token)
                    }
                    this.UP_ME_VIEW(new Date().getTime())
                    this.easyToast("修改成功")
                    setTimeout((e) => {
                        this.easyGoBack()
                    }, 800)
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
    },
}
</script>

<style lang="scss">
.main {
    padding: $app-page-padding;
}

.btn-save {
    margin-top: 40rpx;
    height: 88rpx;
    font-size: 32rpx;
    border-radius: 44rpx;
    color: $app-color-main;
    background: none;
    border: 2rpx solid $app-color-main;
}
.card-group-cell {
    text {
        font-size: 28rpx;
    }
    input {
        font-size: 28rpx;
    }
}
</style>
